/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.tools;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 *
 * @author lenovo-pc
 */
public class SplitJsonArray {

	public static void main(String[] args) throws FileNotFoundException, IOException {
		String sJson = "{Content:[{\"Abstract\":\"\",\"ArticleUrl\":\"\",\"MediaUrl\":\"http://mmbiz.qpic.cn/mmbiz_jpg/InJ4FQSaPnok8qu0MMMtvXeD50MYXIyUia5M53hQKyjs0Q1JQwaXmOKC3I3NbCF5fiaFWSbxSuQ1VfKdPRjZvNsA/0?wx_fmt=jpeg\",\"Title\":\"<p style=\\\"line-height: 25.6px;\\\"><a href=\\\"http://w.url.cn/s/A2QZHDF\\\" target=\\\"_blank\\\" data_ue_src=\\\"http://w.url.cn/s/A2QZHDF\\\"><img data-type=\\\"gif\\\" data-src=\\\"http://mmbiz.qpic.cn/mmbiz_gif/InJ4FQSaPnok8qu0MMMtvXeD50MYXIyUNzPrCcw3tA5kd2JWYUibyXd5Y8PtjroCicZDjoqx6GLo9fgrkUwfHiclQ/0?wx_fmt=gif\\\" data-ratio=\\\"1.6078125\\\" data-w=\\\"640\\\"  /></a><br  /></p><p style=\\\"line-height: 25.6px; text-align: center;\\\"><span style=\\\"font-size: 10px; color: rgb(255, 255, 255);\\\">Nutrilon</span></p>\",\"TxtContent\":\"================\",\"TxtFile\":\"\"},{\"Abstract\":\"\",\"ArticleUrl\":\"\",\"MediaUrl\":\"http://mmbiz.qpic.cn/mmbiz/InJ4FQSaPnoRgJ2v02MA4Hic6gp3yyUbhQ3mwh2XNDAQUkpU7U6dt898gGCVgTDsicicW9tf8Y8cvLPYUIIndMeOQ/0?wx_fmt=jpeg\",\"Title\":\"<section style=\\\"box-sizing: border-box; background-color: rgb(255, 255, 255);\\\"><section class=\\\"Powered-by-XIUMI V5\\\" style=\\\"   box-sizing: border-box; \\\" powered-by=\\\"xiumi.us\\\"><section class=\\\"\\\" style=\\\" margin-top: 10px; margin-bottom: 10px;  box-sizing: border-box; \\\"><section class=\\\"\\\" style=\\\"width: 2.5em; margin-left: auto; box-sizing: border-box;\\\"><section style=\\\"width: 2.5em; border-top-width: 1px; border-top-style: solid; border-top-color: rgb(0, 148, 226); box-sizing: border-box;\\\"></section><section style=\\\"height: 1.4em; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(0, 148, 226); margin-top: -0.5em; margin-left: 2em; box-sizing: border-box;\\\"></section></section><section class=\\\"\\\" style=\\\"padding-right: 0.5em; padding-left: 0.5em; box-sizing: border-box;\\\"><section class=\\\"\\\" style=\\\"padding: 10px; box-sizing: border-box;\\\"><section class=\\\"Powered-by-XIUMI V5\\\" style=\\\"box-sizing: border-box;\\\" powered-by=\\\"xiumi.us\\\"><section class=\\\"\\\" style=\\\"   box-sizing: border-box; \\\"><section class=\\\"\\\" stylhttp://mmbiz.qpic.cn/mmbiz/InJ4FQSaPnoRgJ2v02MA4Hic6gp3yyUbhQ3mwh2XNDAQUkpU7U6dt898gGCVgTDsicicW9tf8Y8cvLPYUIIndMeOQ/0?wx_fmt=jpeg\",\"TxtContent\":\"\",\"TxtFile\":\"\"},{\"Abstract\":\"\",\"ArticleUrl\":\"\",\"MediaUrl\":\"http://mmbiz.qpic.cn/mmbiz_jpg/InJ4FQSaPnpicyQfDVYOA2Ye7bHudXHeo4tUVsJXNbRNsRicUmAYrqRtKstFfGs7LZVSAYlJJjjxgIaEW8APzibeQ/0?wx_fmt=jpeg\",\"Title\":\"<section style=\\\"box-sizing: border-box; background-color: rgb(255, 255, 255);\\\"><section class=\\\"Powered-by-XIUMI V5\\\" style=\\\"   box-sizing: border-box; \\\" powered-by=\\\"xiumi.us\\\"><section class=\\\"\\\" style=\\\" margin-top: 10px; margin-bottom: 10px;  box-sizing: border-box; \\\"><section class=\\\"\\\" style=\\\"width: 2.5em; margin-left: auto; box-sizing: border-box;\\\"><section style=\\\"width: 2.5em; border-top-width: 1px; border-top-style: solid; border-top-color: rgb(0, 148, 226); box-sizing: border-box;\\\"></section><section style=\\\"height: 1.4em; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(0, 148, 226); margin-top: -0.5em; margin-left: 2em; box-sizing: border-box;\\\"></section></section><section class=\\\"\\\" style=\\\"padding-right: 0.5em; padding-left: 0.5em; box-sizing: border-box;\\\"><section class=\\\"\\\" style=\\\"padding: 10px; box-sizing: border-box;\\\"><section class=\\\"Powered-by-XIUMI V5\\\" style=\\\"box-sizing: border-box;\\\" powered-by=\\\"xiumi.us\\\"><section class=\\\"\\\" style=\\\"   box-sizing: border-box; \\\"><section class=\\\"\\\" stylhttp://mmbiz.qpic.cn/mmbiz_jpg/InJ4FQSaPnpicyQfDVYOA2Ye7bHudXHeo4tUVsJXNbRNsRicUmAYrqRtKstFfGs7LZVSAYlJJjjxgIaEW8APzibeQ/0?wx_fmt=jpeg\",\"TxtContent\":\"\",\"TxtFile\":\"\"},{\"Abstract\":\"\",\"ArticleUrl\":\"\",\"MediaUrl\":\"http://mmbiz.qpic.cn/mmbiz_jpg/InJ4FQSaPnrlc511wNpKUmiaEp65QCFic0icPy8IkWWcSpqnBicW7wUTI5icsticASpKkJJ7oPfLF6glUdDgTYcsEDfQ/0?wx_fmt=jpeg\",\"Title\":\"<p><a href=\\\"http://w.url.cn/s/AmXLuIm\\\" target=\\\"_blank\\\" data_ue_src=\\\"http://w.url.cn/s/AmXLuIm\\\"><img data-s=\\\"300,640\\\" data-type=\\\"jpeg\\\" data-src=\\\"http://mmbiz.qpic.cn/mmbiz_jpg/InJ4FQSaPnrlc511wNpKUmiaEp65QCFic0sOZVIrl5kegukx7UE1ibMdpbJnMeXxcYjZ32YYcbzFTic6nyOzoiaTPSA/0?wx_fmt=jpeg\\\" data-ratio=\\\"0.6453125\\\" data-w=\\\"640\\\"  /></a><span style=\\\"font-size: 10px; color: rgb(255, 255, 255);\\\">加入优妈会</span><br  /></p>\",\"TxtContent\":\"\",\"TxtFile\":\"\"}]}";

		StringBuffer sb = new StringBuffer("");

		FileReader reader = new FileReader("D://test_imsg");
		BufferedReader br = new BufferedReader(reader);

		String str = null;

		while ((str = br.readLine()) != null) {
			sb.append(str + "/n");

			System.out.println(str);
			new SplitJsonArray().paserContent(str);
		}

		br.close();
		reader.close();

	}

	private  ArrayList<String> arrArticleUrl = new ArrayList<>();
	private  ArrayList<String> arrTitle = new ArrayList<>();
	private  ArrayList<String> arrAbstract = new ArrayList<>();
	private  ArrayList<String> arrTxtContent = new ArrayList<>();
	private  ArrayList<String> arrMediaUrl = new ArrayList<>();
	private  ArrayList<String> arrAllData = new ArrayList<>();
	private  HashMap<Integer, ArrayList<String>> MMurl = new HashMap<>();
	private  int count = 1;
	private  JSONObject jsonString = null;

	public  void paserContent(String str) {
                arrArticleUrl.clear();
                arrTitle.clear();
                arrAbstract.clear();
                arrTxtContent.clear();
                arrMediaUrl.clear();
                arrAllData.clear();
		jsonString = JSONObject.fromObject(str);
//		System.out.println(jsonString.get("WxId"));
//		System.out.println(jsonString.get("SendTime"));
		JSONArray jaArray = jsonString.getJSONArray("Content");
		count = jaArray.size();
		for (int i = 0; i < jaArray.size(); i++) {
			JSONObject jo = (JSONObject) jaArray.get(i);
			//System.out.println(jo.get("MediaUrl"));
			arrArticleUrl.add(jo.get("ArticleUrl").toString());
			arrTitle.add(jo.get("Title").toString());
			arrAbstract.add(jo.get("Abstract").toString());
			arrTxtContent.add(jo.get("TxtContent").toString());
			arrMediaUrl.add(jo.get("MediaUrl").toString());
			arrAllData.add(jo.get("Title").toString() + jo.get("TxtContent").toString());

		}
//		System.out.println(getArrArticleUrl());
//		System.out.println(getArrTitle());
//		System.out.println(getArrAbstract());
//		System.out.println(getArrTxtContent());
//		System.out.println(getArrMediaUrl());
//		System.out.println(getArrAllData());
//		System.out.println(getArrAllData().get(3));

		for (int i = 0; i < getArrAllData().size(); i++) {
			MMurl.put(i, SplitMMurl.splitMMUrl(getArrAllData().get(i)));
		}
		//System.out.println(getMMurl());
		//System.out.println(getCount());
	}

	public  ArrayList<String> getArrArticleUrl() {
		return arrArticleUrl;
	}

	public  ArrayList<String> getArrTitle() {
		return arrTitle;
	}

	/**
	 * @return the arrAbstract
	 */
	public  ArrayList<String> getArrAbstract() {
		return arrAbstract;
	}

	/**
	 * @return the arrTxtContent
	 */
	public  ArrayList<String> getArrTxtContent() {
		return arrTxtContent;
	}

	/**
	 * @return the arrMediaUrl
	 */
	public  ArrayList<String> getArrMediaUrl() {
		return arrMediaUrl;
	}

	/**
	 * @return the arrAllData
	 */
	public  ArrayList<String> getArrAllData() {
		return arrAllData;
	}

	/**
	 * @return the MMurl
	 */
	public  HashMap<Integer, ArrayList<String>> getMMurl() {
		return MMurl;
	}

	/**
	 * @return the count
	 */
	public  int getCount() {
		return count;
	}

	public  JSONObject getJsonString() {
		return jsonString;
	}
}
